﻿#light

module PubSim.Cups

open System
open Microsoft.FSharp.Control

/// Cups type definition ... used to indicate the number of cups on the
/// cupboard shelf.
type Cups(initValue) =
    let mutable numCups = initValue
    let lockObj = new Object()

    member c.AddCup() =
        lock lockObj (fun() -> numCups <- numCups + 1)
        ignore()
    member c.RemoveCup() =
        lock lockObj (fun() ->
            if numCups > 0 then
                numCups <- numCups - 1
                true
            else
                false
        )
    member c.AddCups(numCupsToAdd) =
        lock lockObj (fun() -> (numCups <- numCups + numCupsToAdd))
        ignore()
    member c.RemoveCups(numCupsToRemove) =
        lock lockObj (fun() -> (numCups <- numCups - numCupsToRemove))
        ignore()
    member c.GetNumCups() = numCups
